import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import { resolve } from "path";
import { fileURLToPath, URL } from "node:url";

export default defineConfig({
    plugins: [
        vue(),
        dts({
            insertTypesEntry: true,
            rollupTypes: true,
            outDir: "dist",
            exclude: ["**/*.test.*", "**/*.spec.*"],
        }),
    ],
    build: {
        lib: {
            entry: resolve(fileURLToPath(new URL(".", import.meta.url)), "src/index.ts"),
            name: "SunAdminCore",
            formats: ["es", "umd"],
            fileName: (format) => `index.${format}.js`,
        },
        rollupOptions: {
            external: [
                "vue",
                "element-plus",
                "@element-plus/icons-vue",
                "pinia",
                "pinia-plugin-persistedstate",
                "vue-router",
                "axios",
            ],
            output: {
                globals: {
                    vue: "Vue",
                    "element-plus": "ElementPlus",
                    "@element-plus/icons-vue": "ElementPlusIconsVue",
                    pinia: "Pinia",
                    "pinia-plugin-persistedstate": "PiniaPluginPersistedstate",
                    "vue-router": "VueRouter",
                    axios: "axios",
                },
                exports: "named",
            },
        },
        cssCodeSplit: false,
        sourcemap: true,
    },
    resolve: {
        alias: {},
    },
});
